#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e6+10;
const int mod = 998244353;

int tot;

struct BIT{
	ll tr[N];
	void add(int x,int y){for(;x <= tot;x += x & -x) tr[x] = (tr[x] + y) % mod;}
	ll query(int x,ll y = 0){for(;x;x -= x & -x) y = (y + tr[x]) % mod;return y;}
}T1,T2;

int a[N],b[N],n,k;
ll ans;

ll qp(ll x,int t){ll res = 1;for(;t;t >>= 1,x = x * x % mod) if(t&1) res=res*x%mod;return res;}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,k = in;
	for(int i = 1;i <= n;i++) a[i] = b[i] = in;
	sort(b + 1,b + n + 1); tot = unique(b + 1,b + n + 1) - b - 1;
	for(int i = 1;i <= n;i++){
		a[i] = lower_bound(b + 1,b + tot + 1 , a[i]) - b;
		if(i > k + 1) T1.add(a[i-k-1],mod-1),T2.add(a[i-k-1],mod - b[a[i-k-1]]);
		ll num = T1.query(a[i]),lef = min(i - 1,k);
		ll tmp = (num * b[a[i]] % mod - T2.query(a[i]) + mod) % mod; ans = (ans + tmp * qp(lef,mod-2)) % mod;
		T1.add(a[i],1); T2.add(a[i],b[a[i]]);
	}ans += b[a[1]]; ans %= mod;
	printf("%lld\n",ans);
	return 0;
}
